﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Manager
{
    public partial class AddPB_CT : Form
    {   private string MPB    =null;
        private string NamePB = null;
        SQL sql = new SQL();
        public AddPB_CT()
        {
            InitializeComponent();
        }
        public AddPB_CT(string @MPB, string @NamePB):this()
        {
            this.MPB = @MPB;
            textBox1.Text = MPB;
            this.NamePB = @NamePB;
            textBox2.Text = NamePB;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string query = "sql_NAMECT_where_MCT";
            DataTable dt = new DataTable();
            dt=sql.getDataTable(query,new SqlParameter ("@MCT",comboBox1.Text));
             if (dt.Rows.Count > 0)
            {
                textBox3.Text = dt.Rows[0][0].ToString();
            }
        }
        private void getMCT()
        {
            string query = "sql_MCT_cb";
            comboBox1.DataSource = sql.getDataTable(query);
            comboBox1.ValueMember = "MCT";
            comboBox1.Text = "";
        }

        private void AddPB_CT_Load(object sender, EventArgs e)
        {
            getMCT();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string query = "sql_update_MPB_where_MCT";
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter("@MPB", textBox2.Text);
            pr[1] = new SqlParameter("@MCT", comboBox1.Text.Trim());

            if (comboBox1.Text != "")
            {
                sql.execute_Query(query, pr);

                MessageBox.Show("Thêm công trình thành công");
                this.Close();
            }
            else
            {
                MessageBox.Show("Ban van chua chon cong trinh nao");
            }
                
                
            
         }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
